//
//  OrderInfoView.m
//  RentTable
//
//  Created by mac on 2024/11/30.
//

#import "OrderInfoView.h"

@interface OrderInfoView()

@property (nonatomic, strong) NSMutableArray<UILabel *> *titleLabels;
@property (nonatomic, strong) NSMutableArray<UILabel *> *infoLabels;

@end

@implementation OrderInfoView

- (instancetype)initWithFrame:(CGRect)frame orderInfo:(NSDictionary *)orderInfo {
    self = [super initWithFrame:frame];
    if (self) {
        _orderInfo = orderInfo;
        _titleLabels = [NSMutableArray array];
        _infoLabels = [NSMutableArray array];
        
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    self.backgroundColor = [UIColor whiteColor];
    
    [self.orderInfo enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *obj, BOOL *stop) {
        [self addRowWithTitle:key info:obj];
    }];
}

- (void)addRowWithTitle:(NSString *)title info:(NSString *)info {
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.text = title;
    titleLabel.textAlignment = NSTextAlignmentLeft;
    titleLabel.font = [UIFont pingFangSCRegularWithSize:16];
    titleLabel.textColor = myRGBHex(0x999999);
    [self addSubview:titleLabel];
    [titleLabel sizeToFit];
    [self.titleLabels addObject:titleLabel];
    
    UILabel *infoLabel = [[UILabel alloc] init];
    infoLabel.text = info;
    infoLabel.textAlignment = NSTextAlignmentRight;
    infoLabel.font = [UIFont pingFangSCMediumWithSize:14];
    infoLabel.textColor = myRGBHex(0x999999);
    [infoLabel sizeToFit];
    [self addSubview:infoLabel];
    [self.infoLabels addObject:infoLabel];
    
    UILabel *lastTitleLabel = self.titleLabels.count > 1 ? self.titleLabels[self.titleLabels.count - 2] : nil;
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(12);
        make.top.equalTo(lastTitleLabel ? lastTitleLabel.mas_bottom : self).offset(12);
        make.height.mas_equalTo(18);
    }];
    
    [infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(-16);
        make.centerY.equalTo(titleLabel.mas_centerY);
        make.height.mas_equalTo(18);
    }];
}


@end
